<!--
 * @description  : 移送变价案件追溯详情
 * @descriptionDetail: 移送变价案件追溯详情
 * @copyright    : 河北烟草
 * @author       : gys
 * @create       : 2024-06-19 08:30:00
-->

<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :custom-back="goBack" style="z-index: 99999" :title="navTitle">
    </theme-navbar>
    <!-- #endif -->
    <view class="content">
      <view class="form-style">
        <view class="form-style-title">
          <view class="left-info-tag"></view>
          <view class="fs-title">基础信息</view>
        </view>
        <view class="peo-sty">
          <view>
            <span class="name">案件编号：</span>
            <span class="val">{{ this.detailInfo.caseCode || '/' }}</span>
          </view>
          <view>
            <span class="name">案发时间：</span>
            <span class="val">{{ this.detailInfo.caseDate || '/' }}</span>
          </view>
          <view>
            <span class="name">处罚日期：</span>
            <span class="val">{{ this.detailInfo.punishDecideDate || '/' }}</span>
          </view>
          <view>
            <span class="name">当事人：</span>
            <span class="val">{{ this.detailInfo.party || '/' }}</span>
          </view>
          <view>
            <span class="name">案由：</span>
            <span class="val">{{ this.detailInfo.caseOfAction || '/' }}</span>
          </view>
          <view>
            <span class="name">承办部门：</span>
            <span class="val">{{ this.detailInfo.orgName || '/' }}</span>
          </view>
          <view>
            <span class="name">承办人：</span>
            <span class="val">{{ this.detailInfo.undertaker || '/' }}</span>
          </view>
          <view>
            <span class="name">仓库名称：</span>
            <span class="val">{{ this.detailInfo.storeName || '/' }}</span>
          </view>
          <view>
            <span class="name">品规数：</span>
            <span class="val">{{ this.detailInfo.specNum || '/' }}</span>
          </view>
          <view>
            <span class="name">总数量：</span>
            <span class="val">{{ this.detailInfo.totalQty || '/' }}</span>
          </view>
        </view>
      </view>

      <view style="border-bottom: 20rpx solid #f2f3f5;margin: 26rpx -56rpx;"></view>

      <view class="form-style" style="line-height: 62rpx;">
        <view class="form-style-title">
          <view class="left-info-tag" style="margin-top:14rpx"></view>
          <view class="fs-title">物品明细</view>
        </view>
        <view class="goods" style="align-items: center;padding-top: 10rpx;">
          <view class="goodsBox" v-for="(item, index) in goodsList" :key="index">
            <view class="title-sty">
              <view class="tags">
                <u-image style="vertical-align: middle;display:inline-block;" src="/static/store/store-home.png"
                  width="48" height="48" />
                <span>{{ item.goodsName }}</span>
              </view>
            </view>
            <view class="peo-sty">
              <!-- <view>
                <span class="name">物品名称</span>
                <span class="val">{{ item.goodsName || '/' }}</span>
              </view> -->
              <view>
                <span class="name">规格</span>
                <span class="val">{{ item.stripCode || '/' }}</span>
              </view>
              <view>
                <span class="name">单位</span>
                <span class="val">{{ item.unit || '/' }}</span>
              </view>
              <view>
                <span class="name">数量</span>
                <span class="val">{{ item.qty || '/' }}</span>
              </view>
              <view>
                <span class="name">物品性质</span>
                <span class="val">{{ item.propTypeName || '/' }}</span>
              </view>
              <!-- <view>
                <span class="name">仓库名称</span>
                <span class="val">{{ item.storeName || '/' }}</span>
              </view>
              <view>
                <span class="name">库位</span>
                <span class="val">{{ item.psCode || '/' }}</span>
              </view> -->
              <view>
                <span class="name">物品数量</span>
                <span class="val"><span class="qty">{{ item.qty || '/' }}</span>{{ item.qty ? '/' :
      '' }}{{ item.unit ? item.unit : '' }}</span>
              </view>
              <!-- <view>
                <span class="name">封箱码</span>
                <span class="val">{{ item.psCode || '/' }}</span>
              </view> -->
            </view>
          </view>
        </view>
      </view>

      <view style="border-bottom: 20rpx solid #f2f3f5;margin: 26rpx -56rpx;"></view>

      <view class="form-style">
        <view class="form-style-title">
          <view class="form-style-title">
            <view class="left-info-tag"></view>
            <view class="fs-title">追溯码</view>
          </view>
          <u-button class="u-btn" size="medium" type="primary" @tap="updown">
            打印
          </u-button>
        </view>
        <view class="qrcodeContainer">
          <!-- <span @tap="updown">下载追溯码</span> -->
          <span>{{ qrmsg }}</span>
          <img :src="qrcodeImg" />
        </view>
      </view>

    </view>
  </view>
</template>

<script>
import { uuid, } from '@/common/util.js';
import storeService from '@/service/store/store.service.js';
export default {
  data() {
    return {
      goodsList: [],
      baseInfo: {},
      isDisabled: true,
      qrcodeImg: null, // 二维码图片
      qrmsg: '追溯码请求中，请稍后。',
    }
  },
  onLoad() {
    this.detailInfo = this.getRouteParam();
    this.detailInfo.uuid = uuid();
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.$modal.showLoading('加载中...');
      // 请求详情信息
      storeService.getHandoverScanDetail({ docId: this.detailInfo.docId }).then(res => {
        if (res.success) {
          this.$modal.hideLoading();
          this.goodsList = res.bean.list;
          this.detailInfo = res.bean;
        } else {
          this.$modal.hideLoading();
          console.log(res);
        }
      }).catch(err => {
        this.$modal.hideLoading();
        console.log(err);
      });
      // 请求二维码
      storeService.getHandoverCaseQr({ docId: this.detailInfo.docId }).then(res => {
        if (res.success) {
          this.$modal.hideLoading();
          this.qrcodeImg = "data:image/png;base64," + res.bean;
          this.qrmsg = ''
        } else {
          this.$modal.hideLoading();
          this.qrmsg = '暂无追溯码';
          console.log(res)
        }
      }).catch(err => {
        this.$modal.hideLoading();
        this.qrmsg = '追溯码请求失败';
        console.log(err)
      });
    },
    // 下载图片
    updown() {
      let objimg = this.qrcodeImg;
      let byteCharacters = atob(objimg.split(',')[1])
      let byteNumbers = new Array(byteCharacters.length)
      for (let i = 0; i < byteCharacters.length; i++) {
        byteNumbers[i] = byteCharacters.charCodeAt(i)
      }
      let byteArray = new Uint8Array(byteNumbers)
      let blobs = 'image/png';
      let url = window.URL.createObjectURL(
        new Blob([byteArray], { type: blobs })
      );
      let link = document.createElement("a"); //创建a标签
      link.style.display = "none"; //将a标签隐藏
      link.href = url; //给a标签添加下载链接
      link.setAttribute("download", '追溯码-' + this.detailInfo.caseCode);
      document.body.appendChild(link);
      link.click(); //执行a标签
    }
  },
}
</script>

<style scoped lang="scss">
.page {
  padding: 28rpx 30rpx;
}

.content {
  padding-bottom: 10rpx;
}

.upload-sty {
  margin-left: -12rpx;
}

.pd-lf {
  padding-left: 0;
}

.pd-tp {
  padding-top: 13px;
}

.content-btn {
  padding: 24rpx 36rpx 20rpx 36rpx;
}

.fs-30 {
  font-size: 30rpx
}

.title-sty {
  padding-bottom: 12rpx;

  .tags {
    display: inline-block;
    width: 100%;
    height: 60rpx;
    text-align: left;
    line-height: 56rpx;
    background: #ECF6FF;
    border-radius: 16rpx;
    margin-right: 20rpx;
  }

  span {
    color: #0070D2;
    font-size: 22rpx;
  }
}

.It-title {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #DADADD;
  padding-bottom: 11px;
  align-items: center;
}

.CT-title {
  font-size: 18px;
  font-weight: bold;
}

.CT-label {
  font-size: 13px;
  color: #989EA1;
  padding-bottom: 6px;
}

.CT-value {
  font-size: 14px;
  color: #393B3D;
}

.form-style-title {
  display: flex;
  justify-content: flex-start;
  flex-direction: row;
  width: 100%;
  align-items: flex-start;
}

.form-style {
  padding: 0rpx 8rpx
}

.left-info-tag {
  padding: 8px 2px;
  background-color: #ee8c4f;
  border-radius: 22px;
  margin: 3px 6px 13px 0px;
}

.left-info-check-tag {
  padding: 8px 2px;
  background-color: #ee8c4f;
  border-radius: 22px;
  margin: 3px 6px 13px 0px;
}

.fs-title {
  font-weight: bold;
  font-size: 32rpx;
}

.loc-box {
  line-height: 38px;
  padding: 11px 0;
  font-size: 13px;
  color: #303133;
}

.peo-sty {
  font-size: 26rpx;

  .name {
    color: #999999;
    font-size: 26rpx;
    margin-right: 20rpx;
    margin-bottom: 20rpx;
    display: inline-block;
    width: 140rpx;
  }

  .val {
    color: #666666;
  }
}

.goods {
  .peo-sty {
    line-height: 22px;
  }

  .name {
    margin-bottom: 0;
    color: #666666;
  }
}

.goodsBox {
  margin-bottom: 40rpx;

  .qty {
    color: #0070D2;
  }
}

.inline-box {
  display: flex;
  align-items: center;
}

.loc-inline {
  font-size: 13px;
  color: #666666;
}

.part-item-info {
  text-align: left;

  .sub-title {
    color: $u-tips-color;
    padding-bottom: 10rpx;
    font-size: 26rpx;
  }

  .main-info {
    color: $u-content-color;
    font-weight: 600;
    margin-bottom: 5px;
  }

  .main-info-color {
    color: $u-content-color;
    font-weight: 600;
    margin-bottom: 5px;
    color: red;
  }
}

.total-sty {
  padding-top: 20rpx;
}

.good-popup-lay {
  padding: $cm-content-paddng-row;
  width: 100%;
  height: 100%;

  &__title {
    font-size: 36rpx;
    font-weight: 600;
    color: $u-main-color;
    margin: 10rpx 0;
    text-align: center;
    width: 100%;
  }

  &__btns {
    width: 100%;
    margin-top: 24rpx;
    display: flex;
    flex-direction: row;
    justify-content: space-between;

    uni-button {
      flex: 0.28;
    }
  }
}

.qrcodeContainer {
  text-align: center;

  img {
    width: 95%;
  }

  p {
    font-size: 18px;
    font-weight: 600;
    color: #333;
  }
}

.u-btn {
  padding: 0 15px;
  height: 30px;
}
</style>